package com.yyt.securitydemo.service;

import com.yyt.securitydemo.dao.UserDao;
import com.yyt.securitydemo.domain.MyUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yeyangtao
 * @since 2022/7/27 16:23
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Resource
    private UserDao userDao;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        MyUser myUser =  userDao.findByUserName(username);
        if (null == myUser) {
            throw new UsernameNotFoundException("用户不存在：" + username);
        }
        return myUser;
    }
}
